import $$ from '../../http.js';

class SystemUsersService {

    constructor() {}

    /* 查询 Users */
    async ApiUsers(payload) {
        console.log('payload:',payload);
        const { offset, pageSize, field } = payload;
        return $$.get(`/api/system/user/list?offset=${offset}&pageSize=${pageSize}&field=${field}`)
    }

    /* 查询 Users */
    async ApiSearchUsers(payload) {
        console.log('payload:',payload);
        const { offset, pageSize, field, name, email, fieldBy, gender } = payload;
        return $$.get(`/api/system/user/search?offset=${offset}&pageSize=${pageSize}&name=${name}&email=${email}&gender=${gender}&fieldBy=${fieldBy}&field=${field}`)
    }

    /* 查询用户Item详情 */
    async ApiUserInfo(payload) {
        console.log('payload:',payload);
        return $$.get(`/api/system/user/${payload.userId}`)
    }

    /* 添加用户Item */
    async ApiUserSave(payload) {
        console.log('payload:',payload);
        return $$.post('/api/system/user', payload)
    }

    /* 更新用户个人信息 */
    async ApiUserUpdate(payload) {
        console.log('payload:',payload);
        return $$.put('/api/system/user', payload)
    }

    /* 更新用户Item状态 */
    async ApiUserStatusUpdate(payload) {
        console.log('payload:',payload);
        return $$.put('/api/system/user/changeStatus', payload)
    }

    /* 删除用户Item */
    async  ApiUserDel(payload) {
        console.log('$$:',payload);
        return $$.delete(`/api/system/user/${payload.userId}`)
    }

    /* 批量删除用户 */
    async  ApiUserBatchDel(payload) {
        console.log('$$:',payload);
        return $$.delete(`/api/system/user/batch/${payload.userIds}`)
    }

    /* 查询授权角色 */
    async ApiUserConfigRoles(payload) {
        console.log('payload:',payload);
        return $$.get(`/api/system/user/authRole/${payload.userId}`)
    }

    /* 添加用户所配角色 */
    async ApiUsersConfigRoleSave(payload) {
        console.log('payload:',payload);
        return $$.put(`/api/system/user/authRole?userId=${payload.userId}&roleIds=${payload.roleIds}`)
    }

    /* 批量添加用户所配角色 */
    async ApiBatchUserRoleSave(payload) {
        console.log('payload:',payload);
        return $$.post(`/api/system/user/batchUserRole`, payload)
    }

}

export const systemUsersService = new SystemUsersService()